package com.dhecp.project.api.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.dhecp.common.utils.RandomValueUtils;
import com.dhecp.common.utils.StringUtils;
import com.dhecp.project.api.domain.*;
import com.dhecp.project.api.mapper.ProductBasisMapper;
import com.dhecp.project.api.mapper.UserInfoMapper;
import com.dhecp.project.api.service.ApiLogService;
import com.dhecp.project.api.service.ApiProductService;
import com.dhecp.project.api.util.ApiCheckUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ApiProductServiceImpl
 * @Description TODO
 * @Author alula
 * @Date 2022-08-25 17:00
 */
@Service
public class ApiProductServiceImpl  implements ApiProductService {

    private static final Logger logger = LoggerFactory.getLogger(ApiProductServiceImpl.class);

    @Autowired
    private ApiLogService apiLogService;

    @Autowired
    private ProductBasisMapper productBasisMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    @Transactional(timeout=120,propagation= Propagation.REQUIRES_NEW)
    public ApiResponse saveProduct(int insertLogId, String system, String type, String appId, String sign, long timestamp, String body) {
        ApiResponse apiResponse = new ApiResponse();
        try {
            String checkResult = ApiCheckUtils.checkPublicParamsValid(appId, sign, timestamp, body, true);
            if (!StringUtils.isEmpty(checkResult)) {
                apiResponse.setCode(400);
                apiResponse.setMessage(checkResult);
                apiLogService.updateApiLog(insertLogId, system, type, "appId：" + appId + "，sign：" + sign + "，timestamp：" + timestamp + "，body：" + body, JSON.toJSONString(apiResponse), apiResponse.getCode(), apiResponse.getMessage());
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return apiResponse;
            }
            List<Map<String, Object>> dataList =  JSONArray.parseObject(body,List.class);
            ProductBasis productBasis = null;
            ProductBasisComponent productBasisComponent = null;
            List<ProductBasisComponent> insertComponentList = null;
            //ProductBasisCompete productBasisCompete =  null;
            List<Map<String, Object>> componentItemList = null;
            Map<String, Object> competeMap = null;
            if (dataList != null && dataList.size() > 0) {
                for (Map<String, Object> item : dataList) {
                    String code = (String) item.get("code");
                    String codeHs = (String) item.get("codeHs");
                    String combination = (String) item.get("combination");
                    String img = (String) item.get("img");
                    String linkIn = (String) item.get("linkIn");
                    String materialCn = (String) item.get("materialCn");
                    String materialEn = (String) item.get("materialEn");
                    String name = (String) item.get("name");
                    String nameCn = (String) item.get("nameCn");
                    String nameEn = (String) item.get("nameEn");
                    String nameUnit = (String) item.get("nameUnit");
                    BigDecimal priceIn = (BigDecimal) item.get("priceIn");
                    int sizeHeight = 0;
                    if (item.containsKey("sizeHeight")){
                        sizeHeight = (int) item.get("sizeHeight");
                    }
                    int sizeLength = 0;
                    if (item.containsKey("sizeLength")){
                        sizeLength = (int) item.get("sizeLength");
                    }
                    int sizeWeight = 0;
                    if (item.containsKey("sizeWeight")){
                        sizeWeight = (int) item.get("sizeWeight");
                    }
                    int sizeWidth = 0;
                    if (item.containsKey("sizeWidth")){
                        sizeWidth = (int) item.get("sizeWidth");
                    }
                    String usageCn = (String) item.get("usageCn");
                    String usageEn = (String) item.get("usageEn");
                    productBasis = new ProductBasis();
                    productBasis.setCode(code);
                    productBasis.setCodeHs(codeHs);
                    productBasis.setCombination(combination);
                    productBasis.setImg(img);
                    productBasis.setLinkIn(linkIn);
                    productBasis.setMaterialCn(materialCn);
                    productBasis.setMaterialEn(materialEn);
                    productBasis.setName(name);
                    productBasis.setNameCn(nameCn);
                    productBasis.setNameEn(nameEn);
                    productBasis.setNameUnit(nameUnit);
                    productBasis.setPriceIn(priceIn.doubleValue());
                    productBasis.setSizeHeight(sizeHeight);
                    productBasis.setSizeLength(sizeLength);
                    productBasis.setSizeWeight(sizeWeight);
                    productBasis.setSizeWidth(sizeWidth);
                    productBasis.setUsageCn(usageCn);
                    productBasis.setUsageEn(usageCn);
                    ProductBasis queryProductBasis = productBasisMapper.findProductBasisByCode(code);
                    if (item.containsKey("subArr")) {
                        componentItemList = (List<Map<String, Object>>)item.get("subArr");
                    }
                    if (item.containsKey("jingPin")) {
                        competeMap = (Map<String, Object>) item.get("jingPin");
                    }
                    if (queryProductBasis == null){//不存在新增
                        productBasis.setGuid(RandomValueUtils.getGUID());
                        UserInfo userInfo = userInfoMapper.findByUserId("0000");
                        if (userInfo != null){
                            productBasis.setCreateUser(userInfo.getUserId());
                            productBasis.setCreateUserName(userInfo.getUserName());
                            productBasis.setCreateDept(userInfo.getDeptPath());
                            productBasis.setCreateDeptName(userInfo.getDeptName());
                            productBasis.setCreatePosition(userInfo.getPositionName());
                        }
                        productBasis.setCreateTime(new Date());
                        //处理jingPin数据
                        if (competeMap != null){
                            String copeAsin = (String) competeMap.get("asin");
                            String copeCateFive = (String) competeMap.get("cateFive");
                            String copeCateFour = (String) competeMap.get("cateFour");
                            String copeCateOne = (String) competeMap.get("cateOne");
                            String copeCateSix = (String) competeMap.get("cateSix");
                            String copeCateThree = (String) competeMap.get("cateThree");
                            String copeCateTwo = (String) competeMap.get("cateTwo");
                            String copeDayOn= (String) competeMap.get("dayOn");
                            String copeDispatches = (String) competeMap.get("dispatches");
                            String copeImg = (String) competeMap.get("img");
                            String copeLink = (String) competeMap.get("link");
                            BigDecimal copePrice= null;
                            if (competeMap.containsKey("price")){
                                copePrice= (BigDecimal) competeMap.get("price");
                            }
                            int copeRankOne = 0;
                            if (competeMap.containsKey("rankOne")) {
                                copeRankOne = (int) competeMap.get("rankOne");
                            }
                            int copeRankTwo = 0;
                            if (competeMap.containsKey("rankTwo")) {
                                copeRankTwo = (int) competeMap.get("rankTwo");
                            }
                            int copeRankThree = 0;
                            if (competeMap.containsKey("rankThree")) {
                                copeRankThree = (int) competeMap.get("rankThree");
                            }
                            String copeRankNameOne= (String) competeMap.get("rankNameOne");
                            String copeRankNameThree= (String) competeMap.get("rankNameThree");
                            String copeRankNameTwo= (String) competeMap.get("rankNameTwo");
                            int copeRating = 0;
                            if (competeMap.containsKey("rating")) {
                                copeRating = (int) competeMap.get("rating");
                            }
                            int copeScore = 0;
                            if (competeMap.containsKey("score")){
                                copeScore = (int) competeMap.get("score");
                            }
                            int copeSizeHeight = 0;
                            if (competeMap.containsKey("sizeHeight")){
                                copeSizeHeight = (int)competeMap.get("sizeHeight");
                            }
                            int copeSizeLength = 0;
                            if (competeMap.containsKey("sizeLength")){
                                copeSizeLength = (int) competeMap.get("sizeLength");
                            }
                            int copeSizeWeight = 0;
                            if (competeMap.containsKey("sizeWeight")){
                                copeSizeWeight = (int) competeMap.get("sizeWeight");
                            }
                            int copeSizeWidth = 0;
                            if (competeMap.containsKey("sizeWidth")){
                                copeSizeWidth = (int) competeMap.get("sizeWidth");
                            }
                            String copeSolder = "";
                            if(competeMap.containsKey("solder")) {
                                copeSolder = (String) competeMap.get("solder");
                            }
                            String copeTitle = "";
                            if(competeMap.containsKey("title")) {
                                copeTitle = (String) competeMap.get("title");
                            }
                            String copeRemark = "";
                            if (competeMap.containsKey("remark")) {
                                copeRemark = (String) competeMap.get("remark");
                            }
                            int fbaCommPercentInt = 0;
                            if (competeMap.containsKey("fbaCommPercentInt")){
                                fbaCommPercentInt = (int) competeMap.get("fbaCommPercentInt");
                            }
                            BigDecimal priceSuggest = null;
                            if (competeMap.containsKey("priceSuggest")){
                                priceSuggest = (BigDecimal) competeMap.get("priceSuggest");
                            }
                            BigDecimal fbaDeleveryExpect = null;
                            if (competeMap.containsKey("fbaDeleveryExpect")){
                                fbaDeleveryExpect = (BigDecimal) competeMap.get("fbaDeleveryExpect");
                            }
                            BigDecimal fbaExpect = null;
                            if (competeMap.containsKey("fbaExpect")){
                                fbaExpect = (BigDecimal) competeMap.get("fbaExpect");
                            }
                            BigDecimal budgetCostByPlane = null;
                            if (competeMap.containsKey("budgetCostByPlane")){
                                budgetCostByPlane = (BigDecimal) competeMap.get("budgetCostByPlane");
                            }
                            BigDecimal budgetCostByShip = null;
                            if (competeMap.containsKey("budgetCostByShip")){
                                budgetCostByShip = (BigDecimal) competeMap.get("budgetCostByShip");
                            }
                            BigDecimal percentBudgetByPlane = null;
                            if (competeMap.containsKey("percentBudgetByPlane")){
                                percentBudgetByPlane = (BigDecimal) competeMap.get("percentBudgetByPlane");
                            }
                            BigDecimal percentBudgetByShip = null;
                            if (competeMap.containsKey("percentBudgetByShip")){
                                percentBudgetByShip = (BigDecimal) competeMap.get("percentBudgetByShip");
                            }
                            BigDecimal percentInoutByPlane = null;
                            if (competeMap.containsKey("percentInoutByPlane")){
                                percentInoutByPlane = (BigDecimal) competeMap.get("percentInoutByPlane");
                            }
                            BigDecimal percentInoutByShip = null;
                            if (competeMap.containsKey("percentInoutByShip")){
                                percentInoutByShip = (BigDecimal) competeMap.get("percentInoutByShip");
                            }
                            BigDecimal priceService = null;
                            if (competeMap.containsKey("priceService")){
                                priceService = (BigDecimal) competeMap.get("priceService");
                            }
                            productBasis.setAsinJP(copeAsin);
                            productBasis.setCateFiveJP(copeCateFive);
                            productBasis.setCateFourJP(copeCateFour);
                            productBasis.setCateOneJP(copeCateOne);
                            productBasis.setCateSixJP(copeCateSix);
                            productBasis.setCateThreeJP(copeCateThree);
                            productBasis.setCateTwoJP(copeCateTwo);
                            productBasis.setDayOnJP(copeDayOn);
                            productBasis.setDispatchesJP(copeDispatches);
                            productBasis.setImgJP(copeImg);
                            productBasis.setLinkJP(copeLink);
                            productBasis.setPriceJP(((copePrice != null) ? copePrice.doubleValue() : 0));
                            productBasis.setRankOneJP(copeRankOne);
                            productBasis.setRankNameOneJP(copeRankNameOne);
                            productBasis.setRankTwoJP(copeRankTwo);
                            productBasis.setRankNameTwoJP(copeRankNameTwo);
                            productBasis.setRankThreeJP(copeRankThree);
                            productBasis.setRankNameThreeJP(copeRankNameThree);
                            productBasis.setRatingJP(copeRating);
                            productBasis.setScoreJP((double)copeScore);
                            productBasis.setSizeLengthJP(copeSizeLength);
                            productBasis.setSizeHeightJP(copeSizeHeight);
                            productBasis.setSizeWeightJP(copeSizeWeight);
                            productBasis.setSizeWidthJP(copeSizeWidth);
                            productBasis.setSolderJP(copeSolder);
                            productBasis.setTitleJP(copeTitle);
                            productBasis.setRemarkJP(copeRemark);
                            productBasis.setfYjb((double)fbaCommPercentInt);
                            productBasis.setfJySj(((priceSuggest != null) ? priceSuggest.doubleValue() : 0));
                            productBasis.setfWlYgFy(((fbaDeleveryExpect != null) ? fbaDeleveryExpect.doubleValue() : 0));
                            productBasis.setfYgFy(((fbaExpect != null) ? fbaExpect.doubleValue() : 0));
                            productBasis.setfCbK(((budgetCostByPlane != null) ? budgetCostByPlane.doubleValue() : 0));
                            productBasis.setfCbH(((budgetCostByShip != null) ? budgetCostByShip.doubleValue() : 0));
                            productBasis.setfMllK(((percentBudgetByPlane != null) ? percentBudgetByPlane.doubleValue() : 0));
                            productBasis.setfMllH(((percentBudgetByShip != null) ? percentBudgetByShip.doubleValue() : 0));
                            productBasis.setfTcbK(((percentInoutByPlane != null) ? percentInoutByPlane.doubleValue() : 0));
                            productBasis.setfTcbH(((percentInoutByShip != null) ? percentInoutByShip.doubleValue() : 0));
                            productBasis.setPriceService(((priceService != null) ? priceService.doubleValue() : 0));
                        }
                        productBasisMapper.insertProductBasis(productBasis);
                        //处理subArr数据
                        if (componentItemList != null && componentItemList.size() > 0){
                            insertComponentList = new ArrayList<>();
                            for (Map<String, Object> compItem : componentItemList) {
                                String compCode = (String) compItem.get("code");
                                String compName = (String) compItem.get("name");
                                int compNum = 0;
                                if (compItem.containsKey("num")){
                                    compNum = (int) compItem.get("num");
                                }
                                String compRemark = (String) compItem.get("remark");
                                productBasisComponent = new ProductBasisComponent();
                                productBasisComponent.setGuid(RandomValueUtils.getGUID());
                                productBasisComponent.setPcode(code);
                                productBasisComponent.setCode(compCode);
                                productBasisComponent.setName(name);
                                productBasisComponent.setNum(compNum);
                                productBasisComponent.setRemark(compRemark);
                                productBasisComponent.setCreateUser("0000");
                                productBasisComponent.setCreateTime(new Date());
                                productBasisComponent.setUpdateUser("0000");
                                productBasisComponent.setUpdateTime(new Date());
                                insertComponentList.add(productBasisComponent);
                            }
                            if (insertComponentList != null && insertComponentList.size() > 0){
                                productBasisMapper.insertProductBasisComponentBatch(insertComponentList);
                            }
                        }

                    }else{//存在修改
                        productBasis.setGuid(queryProductBasis.getGuid());
                        productBasis.setUpdateUser("0000");
                        productBasis.setUpdateTime(new Date());
                        //处理jingPin数据
                        if (competeMap != null){
                            String copeAsin = (String) competeMap.get("asin");
                            String copeCateFive = (String) competeMap.get("cateFive");
                            String copeCateFour = (String) competeMap.get("cateFour");
                            String copeCateOne = (String) competeMap.get("cateOne");
                            String copeCateSix = (String) competeMap.get("cateSix");
                            String copeCateThree = (String) competeMap.get("cateThree");
                            String copeCateTwo = (String) competeMap.get("cateTwo");
                            String copeDayOn= (String) competeMap.get("dayOn");
                            String copeDispatches = (String) competeMap.get("dispatches");
                            String copeImg = (String) competeMap.get("img");
                            String copeLink = (String) competeMap.get("link");
                            BigDecimal copePrice= null;
                            if (competeMap.containsKey("price")){
                                copePrice= (BigDecimal) competeMap.get("price");
                            }
                            int copeRankOne = 0;
                            if (competeMap.containsKey("rankOne")) {
                                copeRankOne = (int) competeMap.get("rankOne");
                            }
                            int copeRankTwo = 0;
                            if (competeMap.containsKey("rankTwo")) {
                                copeRankTwo = (int) competeMap.get("rankTwo");
                            }
                            int copeRankThree = 0;
                            if (competeMap.containsKey("rankThree")) {
                                copeRankThree = (int) competeMap.get("rankThree");
                            }
                            String copeRankNameOne= (String) competeMap.get("rankNameOne");
                            String copeRankNameThree= (String) competeMap.get("rankNameThree");
                            String copeRankNameTwo= (String) competeMap.get("rankNameTwo");
                            int copeRating = 0;
                            if (competeMap.containsKey("rating")) {
                                copeRating = (int) competeMap.get("rating");
                            }
                            int copeScore = 0;
                            if (competeMap.containsKey("score")){
                                copeScore = (int) competeMap.get("score");
                            }
                            int copeSizeHeight = 0;
                            if (competeMap.containsKey("sizeHeight")){
                                copeSizeHeight = (int)competeMap.get("sizeHeight");
                            }
                            int copeSizeLength = 0;
                            if (competeMap.containsKey("sizeLength")){
                                copeSizeLength = (int) competeMap.get("sizeLength");
                            }
                            int copeSizeWeight = 0;
                            if (competeMap.containsKey("sizeWeight")){
                                copeSizeWeight = (int) competeMap.get("sizeWeight");
                            }
                            int copeSizeWidth = 0;
                            if (competeMap.containsKey("sizeWidth")){
                                copeSizeWidth = (int) competeMap.get("sizeWidth");
                            }
                            String copeSolder = "";
                            if(competeMap.containsKey("solder")) {
                                copeSolder = (String) competeMap.get("solder");
                            }
                            String copeTitle = "";
                            if(competeMap.containsKey("title")) {
                                copeTitle = (String) competeMap.get("title");
                            }
                            String copeRemark = "";
                            if (competeMap.containsKey("remark")) {
                                copeRemark = (String) competeMap.get("remark");
                            }
                            int fbaCommPercentInt = 0;
                            if (competeMap.containsKey("fbaCommPercentInt")){
                                fbaCommPercentInt = (int) competeMap.get("fbaCommPercentInt");
                            }
                            BigDecimal priceSuggest = null;
                            if (competeMap.containsKey("priceSuggest")){
                                priceSuggest = (BigDecimal) competeMap.get("priceSuggest");
                            }
                            BigDecimal fbaDeleveryExpect = null;
                            if (competeMap.containsKey("fbaDeleveryExpect")){
                                fbaDeleveryExpect = (BigDecimal) competeMap.get("fbaDeleveryExpect");
                            }
                            BigDecimal fbaExpect = null;
                            if (competeMap.containsKey("fbaExpect")){
                                fbaExpect = (BigDecimal) competeMap.get("fbaExpect");
                            }
                            BigDecimal budgetCostByPlane = null;
                            if (competeMap.containsKey("budgetCostByPlane")){
                                budgetCostByPlane = (BigDecimal) competeMap.get("budgetCostByPlane");
                            }
                            BigDecimal budgetCostByShip = null;
                            if (competeMap.containsKey("budgetCostByShip")){
                                budgetCostByShip = (BigDecimal) competeMap.get("budgetCostByShip");
                            }
                            BigDecimal percentBudgetByPlane = null;
                            if (competeMap.containsKey("percentBudgetByPlane")){
                                percentBudgetByPlane = (BigDecimal) competeMap.get("percentBudgetByPlane");
                            }
                            BigDecimal percentBudgetByShip = null;
                            if (competeMap.containsKey("percentBudgetByShip")){
                                percentBudgetByShip = (BigDecimal) competeMap.get("percentBudgetByShip");
                            }
                            BigDecimal percentInoutByPlane = null;
                            if (competeMap.containsKey("percentInoutByPlane")){
                                percentInoutByPlane = (BigDecimal) competeMap.get("percentInoutByPlane");
                            }
                            BigDecimal percentInoutByShip = null;
                            if (competeMap.containsKey("percentInoutByShip")){
                                percentInoutByShip = (BigDecimal) competeMap.get("percentInoutByShip");
                            }
                            BigDecimal priceService = null;
                            if (competeMap.containsKey("priceService")){
                                priceService = (BigDecimal) competeMap.get("priceService");
                            }
                            productBasis.setAsinJP(copeAsin);
                            productBasis.setCateFiveJP(copeCateFive);
                            productBasis.setCateFourJP(copeCateFour);
                            productBasis.setCateOneJP(copeCateOne);
                            productBasis.setCateSixJP(copeCateSix);
                            productBasis.setCateThreeJP(copeCateThree);
                            productBasis.setCateTwoJP(copeCateTwo);
                            productBasis.setDayOnJP(copeDayOn);
                            productBasis.setDispatchesJP(copeDispatches);
                            productBasis.setImgJP(copeImg);
                            productBasis.setLinkJP(copeLink);
                            productBasis.setPriceJP(((copePrice != null) ? copePrice.doubleValue() : 0));
                            productBasis.setRankOneJP(copeRankOne);
                            productBasis.setRankNameOneJP(copeRankNameOne);
                            productBasis.setRankTwoJP(copeRankTwo);
                            productBasis.setRankNameTwoJP(copeRankNameTwo);
                            productBasis.setRankThreeJP(copeRankThree);
                            productBasis.setRankNameThreeJP(copeRankNameThree);
                            productBasis.setRatingJP(copeRating);
                            productBasis.setScoreJP((double)copeScore);
                            productBasis.setSizeLengthJP(copeSizeLength);
                            productBasis.setSizeHeightJP(copeSizeHeight);
                            productBasis.setSizeWeightJP(copeSizeWeight);
                            productBasis.setSizeWidthJP(copeSizeWidth);
                            productBasis.setSolderJP(copeSolder);
                            productBasis.setTitleJP(copeTitle);
                            productBasis.setRemarkJP(copeRemark);
                            productBasis.setfYjb((double)fbaCommPercentInt);
                            productBasis.setfJySj(((priceSuggest != null) ? priceSuggest.doubleValue() : 0));
                            productBasis.setfWlYgFy(((fbaDeleveryExpect != null) ? fbaDeleveryExpect.doubleValue() : 0));
                            productBasis.setfYgFy(((fbaExpect != null) ? fbaExpect.doubleValue() : 0));
                            productBasis.setfCbK(((budgetCostByPlane != null) ? budgetCostByPlane.doubleValue() : 0));
                            productBasis.setfCbH(((budgetCostByShip != null) ? budgetCostByShip.doubleValue() : 0));
                            productBasis.setfMllK(((percentBudgetByPlane != null) ? percentBudgetByPlane.doubleValue() : 0));
                            productBasis.setfMllH(((percentBudgetByShip != null) ? percentBudgetByShip.doubleValue() : 0));
                            productBasis.setfTcbK(((percentInoutByPlane != null) ? percentInoutByPlane.doubleValue() : 0));
                            productBasis.setfTcbH(((percentInoutByShip != null) ? percentInoutByShip.doubleValue() : 0));
                            productBasis.setPriceService(((priceService != null) ? priceService.doubleValue() : 0));
                        }
                        productBasisMapper.updateProductBasis(productBasis);
                        //处理subArr数据
                        if (componentItemList != null && componentItemList.size() > 0){
                            insertComponentList = new ArrayList<>();
                            for (Map<String, Object> compItem : componentItemList) {
                                String compCode = (String) compItem.get("code");
                                String compName = (String) compItem.get("name");
                                int compNum = 0;
                                if (compItem.containsKey("num")){
                                    compNum = (int) compItem.get("num");
                                }
                                String compRemark = (String) compItem.get("remark");
                                productBasisComponent = new ProductBasisComponent();
                                productBasisComponent.setGuid(RandomValueUtils.getGUID());
                                productBasisComponent.setPcode(code);
                                productBasisComponent.setCode(compCode);
                                productBasisComponent.setName(name);
                                productBasisComponent.setNum(compNum);
                                productBasisComponent.setRemark(compRemark);
                                productBasisComponent.setCreateUser("0000");
                                productBasisComponent.setCreateTime(new Date());
                                productBasisComponent.setUpdateUser("0000");
                                productBasisComponent.setUpdateTime(new Date());
                                insertComponentList.add(productBasisComponent);
                            }
                            if (insertComponentList != null && insertComponentList.size() > 0){
                                productBasisMapper.deleteProductBasisCompeteBypcode(code);//修改先删除数据再新增
                                productBasisMapper.insertProductBasisComponentBatch(insertComponentList);
                            }
                        }
                    }
                }
            }
            apiResponse.setSuccess(true);
            apiResponse.setCode(0);
            apiLogService.updateApiLog(insertLogId, system, type, "appId："+appId +"，sign："+sign +"，timestamp：" +timestamp + "，body：" +body, JSON.toJSONString(apiResponse), apiResponse.getCode(), apiResponse.getMessage());
        }catch (Exception ex){
            apiResponse.setCode(500);
            apiResponse.setMessage("ECP_API接口处理产品采集系统传送产品数据保存出错，具体错误信息为："+ex.getMessage());
            logger.error("ECP_API接口处理产品采集系统传送产品数据保存出错，错误信息为：" + ex.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return  apiResponse;
    }

}
